import os
from pathlib import Path



AppId = "wxa78169eeb3e130bc"  # 写你自己的小程序的id默认配置，直接写在setting里面

AppSecret = "eb7112918a20263bf6517fffb92c9c4a"  # 写你自己的小程序的秘钥
code2Session = "https://api.weixin.qq.com/sns/jscode2session?appid={}&secret={}&js_code={}&grant_type=authorization_code"

BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = "django-insecure-2e@27c=*yvu8g92&n0u509exl1(#*d0s)$mwou$nv3_i0@4e55"

DEBUG = True

ALLOWED_HOSTS = ['*']


INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "user.apps.UserConfig",

    "rest_framework",

    "rest_framework_simplejwt",
    # jwt权限校验
    # pip install djangorestframework-simplejwt 要安装一下

    'corsheaders',  # 跨域

]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    # "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    'corsheaders.middleware.CorsMiddleware',  # 加入中间键
]

ROOT_URLCONF = "DjangoPro1.urls"

MEDIA_URL = '/docker_media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'docker_media/')

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ],

        },
    },
]

# wsgi目录
WSGI_APPLICATION = "DjangoPro1.wsgi.application"


DATABASES = {
    # 默认使用mysql数据库
    "default": {
        "ENGINE": "django.db.backends.mysql",  # 数据库引擎
        "NAME": "dev",  # 数据库名
        "USER": "root",  # 用户名
        "PASSWORD": "123456",  # 密码
        "HOST": "localhost",  # 远程数据库主机地址（IP 或域名）
        "POST": 3306,  # 端口
        "OPTIONS": {"charset": "utf8mb4"},
    },
}

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
    },
    {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", },
    {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", },
    {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", },
]

LANGUAGE_CODE = "zh-hans"

TIME_ZONE = "Asia/Shanghai"

USE_I18N = True

USE_TZ = True

STATIC_URL = "static/"

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

REST_FRAMEWORK = {
    # 配置登录鉴权方式
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
    ),
}

CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_HEADERS = ['*']
CORS_ALLOW_METHODS = ['*']
